package com.efast.dmom.mes.bean;

import java.util.Comparator;

import com.efast.dmom.mes.bean.base.BaseBean;
import com.efast.dmom.mes.entity.PlanOrderEntity;

/**
 * @author Aaron Liu
 *
 * @date:2020年2月6日
 */
public class PlanOrder extends BaseBean<PlanOrderEntity> {

	private static final long serialVersionUID = 8543836349770694468L;

	private PlanOrderEntity innerData = null;

	public PlanOrderEntity getInnerData() {
		return innerData;
	}

	public void setInnerData(PlanOrderEntity innerData) {
		this.innerData = innerData;
	}

	public static Comparator<PlanOrder> productionComparator = new Comparator<PlanOrder>() {

		@Override
		public int compare(PlanOrder order1, PlanOrder order2) {

			if (order1 == null) {
				return -1;
			}
			if (order2 == null) {
				return 1;
			}

			PlanOrderEntity entity1 = order1.getInnerData();
			PlanOrderEntity entity2 = order2.getInnerData();

			if (entity1.getPriority() > entity2.getPriority()) {
				return -1;
			}

			if (entity1.getPriority() < entity2.getPriority()) {
				return 1;
			}

			if (entity1.getPriority() == entity2.getPriority()) {

				if (entity1.getPlanOfflineDate().isBefore(entity2.getPlanOfflineDate()))
					return -1;
				else if (entity1.getPlanOfflineDate().isAfter(entity2.getPlanOfflineDate())) {
					return 1;
				}
			}
			return 0;
		}
	};

	public static Comparator<PlanOrder> timeComparator = new Comparator<PlanOrder>() {

		@Override
		public int compare(PlanOrder order1, PlanOrder order2) {

			if (order1 == null) {
				return -1;
			}
			if (order2 == null) {
				return 1;
			}

			PlanOrderEntity entity1 = order1.getInnerData();
			PlanOrderEntity entity2 = order2.getInnerData();

			if (entity1.getPlanOfflineDate() == null) {
				return -1;
			}

			if (entity1.getPlanOfflineDate() == null) {
				return 1;
			}

			if (entity1.getPlanOfflineDate().isBefore(entity2.getPlanOfflineDate()))
				return -1;
			else if (entity1.getPlanOfflineDate().isAfter(entity2.getPlanOfflineDate())) {
				return 1;
			}

			return 0;
		}
	};

	public boolean equals(Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj != null && obj instanceof PlanOrder) {

			PlanOrder order = (PlanOrder) obj;

			return this.getInnerData().getId() == order.getInnerData().getId()
					|| this.getInnerData().getOrderNumber().equals(order.getInnerData().getOrderNumber());

		} else {
			return false;
		}
	}

}
